package com.zjht.gmcc.servlet.pdt;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;

public class ProductDelete extends BaseServlet {
	private static final long serialVersionUID = 1L;

	public boolean process(HttpServletRequest request, HttpServletResponse response,
			HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)
			throws Exception {
		String typeid = request.getParameter("typeid");
		int i_flag=0;
		
		StringBuilder s_sql = new StringBuilder();
		s_sql.append ("delete producttype where  parenttypeid in (select typeid from producttype where parenttypeid=?)");
		PreparedStatement ps1 = myJDBC.prepareStatement(s_sql);
		ps1.setString(1, typeid);
		i_flag=ps1.executeUpdate();
		
		s_sql = new StringBuilder();
		s_sql.append("delete producttype where parenttypeid=?");
		ps1=myJDBC.prepareStatement(s_sql);
		ps1.setString(1, typeid);
		i_flag=ps1.executeUpdate();
		
		s_sql = new StringBuilder();
		s_sql.append("delete producttype where typeid=?");
		ps1=myJDBC.prepareStatement(s_sql);
		ps1.setString(1, typeid);
		i_flag=ps1.executeUpdate();
		ps1.close();
		ps1 = null;
		
		
		String url = "products.jsp";
		String act = "该大类删除";
		if (i_flag > 0) {
			alert(out, act + "成功", url);
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return i_flag > 0;
	}
}
